<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:sec="http://www.springframework.org/security/tags"
	xmlns:pe="http://primefaces.org/ui/extensions"
	xmlns:p="http://primefaces.org/ui">

<f:view locale="#{localeSwitcher.locale}">

	<h:head>
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="viewport"
			content="width=device-width, initial-scale=1.0, user-scalable=no" />
		<h:outputScript library="primefaces" name="jquery/jquery.js" />

		<h:outputStylesheet name="css/style.css" />
		<h:outputStylesheet name="css/page.css" />

		<title><ui:insert name="pageTitle"></ui:insert></title>
		<ui:insert name="head-extra" />
	</h:head>

	<h:body>
		<ui:insert name="dialogs" />
		<p:layout styleClass="userLayout" fullPage="false"
			widgetVar="layoutWdgt"
			style="min-height:2000px; min-width: 1100px; margin: 0 auto;">
			<p:layoutUnit position="north" id="head" resizable="false"
				styleClass="headerLayout">
				<h:form>
					<p:toolbar id="tb" style="overflow:hidden;">
						<f:facet name="left">
							<p:commandButton
								action="#{menuView.redirectToUrl('/pages/unsecure/index.xhtml')}"
								value="Home" icon="ui-icon-document" />
							<p:commandButton
								action="#{menuView.redirectToUrl('/pages/secure/user/category-product.xhtml')}"
								value="Product" icon="ui-icon-document" />
							<p:autoComplete id="Categorys"
								value="#{menuView.selectedProduct}"
								completeMethod="#{menuView.completeText}" var="c"
								itemLabel="#{c.name}" itemValue="#{c}" label="Search Product"
								converter="productConverterOfMenuView" />
							<p:commandButton value="Open" icon="ui-icon-folder-open"
								action="#{menuView.redirectToCompleteText()}" />

						</f:facet>
						<f:facet name="right">
							<sec:authorize ifAnyGranted="ROLE_ANONYMOUS">
								<p:commandButton icon="ui-icon-disk" value="Login"
									action="#{menuView.redirectToUrl('/pages/unsecure/login.xhtml')}" />
								<p:commandButton icon="ui-icon-disk" value="Sign up"
									action="#{menuView.redirectToUrl('/pages/unsecure/signup.xhtml')}" />
							</sec:authorize>
							<sec:authorize
								ifAnyGranted="ROLE_ADMIN,ROLE_IMPORTER,ROLE_EXPORTER,ROLE_LEADER,ROLE_PARTNER_MANAGER,ROLE_PRODUCT_MANAGER">
								<p:commandButton icon="ui-icon-disk" value="Admin"
									action="#{menuView.redirectToUrl('/pages/secure/admin/index.xhtml')}" />
							</sec:authorize>
						</f:facet>
					</p:toolbar>
				</h:form>
			</p:layoutUnit>
			<p:layoutUnit position="center" resizable="false"
				styleClass="contentLayout contentLayoutBorder">
				<ui:insert name="content" />
			</p:layoutUnit>
			<p:layoutUnit position="east" size="220" resizeWhileDragging="true"
				styleClass="cartLayout contentLayoutBorder" resizable="true"
				collapsible="true">
				<f:facet name="header">
					<h:outputText value="Cart" />
				</f:facet>
				<h:form id="cart">
					<sec:authorize ifAnyGranted="ROLE_USER">
						<h3>
							<h:outputText value="Logged as: #{request.userPrincipal.name}" />
						</h3>
						<p:menu toggleable="true" style="margin:0 auto;">
							<p:submenu label="Profile">
								<p:menuitem value="Show profile"
									outcome="/pages/secure/user/profile.xhtml" />
								<p:menuitem value="Log out" url="/j_spring_security_logout"
									icon="ui-icon-extlink" />
							</p:submenu>
							<p:submenu label="Orders">
								<p:menuitem value="Orders- status"
									outcome="/pages/secure/user/order-status.xhtml" />
							</p:submenu>
						</p:menu>
						<br />
						<p:separator style="height:10px;" />
						<br />
					</sec:authorize>
					<p:dataGrid value="#{cartController.cart}" var="product"
						type="definition" id="list" columns="1">

						<f:facet name="header">
					           Cart Items: 
					        </f:facet>
						<p:fieldset legend="#{product.product.name}"
							style="margin-bottom:2px">
							<h:panelGrid columns="3">
								<h:outputText value="#{product.cost} HUF" />
								<h:outputText value=" ( #{product.quantity} )" />
								<p:commandButton icon="ui-icon-disk"
									action="#{cartController.removeElementFromCart(product)}"
									update=":cart" />
							</h:panelGrid>
						</p:fieldset>
					</p:dataGrid>
					<p:panelGrid columns="2">
						<h:outputText value="Cost:" />
						<h:outputText value="#{cartController.cost}" />
					</p:panelGrid>
					<br />
					<p:button value="Order" disabled="#{cartController.cart.size()==0}"
						href="/pages/secure/user/create-order.xhtml" />
					<p:commandButton value="Remove all"
						action="#{cartController.removeAll()}" update=":cart"
						disabled="#{cartController.cart.size()==0}" />
				</h:form>
			</p:layoutUnit>
		</p:layout>

	</h:body>

</f:view>
</html>
